package bid.yanhj.springboot.pojo;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "t_roles")
public class Roles {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "roleid")
    private Integer roleid;

    @Column(name = "rolename")
    private String rolename;

    @OneToMany(mappedBy = "roles")
    private Set<Users> users = new HashSet<>();
    
    @ManyToMany(cascade = CascadeType.PERSIST, fetch=FetchType.EAGER)
    // @JoinTable  映射中间表
    // joinColumns 当前表的主键所关联中间表外键字段
    // role_id
    @JoinTable(name="t_roles_menus", joinColumns=@JoinColumn(name = "role_id"), inverseJoinColumns=@JoinColumn(name = "menu_id"))
    private Set<Menus> menus = new HashSet<>();

    /**
     * @return the menus
     */
    public Set<Menus> getMenus() {
        return menus;
    }

    /**
     * @param menus the menus to set
     */
    public void setMenus(Set<Menus> menus) {
        this.menus = menus;
    }

    /**
     * @return the roleid
     */
    public Integer getRoleid() {
        return roleid;
    }

    /**
     * @param roleid
     *            the roleid to set
     */
    public void setRoleid(Integer roleid) {
        this.roleid = roleid;
    }

    /**
     * @return the rolename
     */
    public String getRolename() {
        return rolename;
    }

    /**
     * @param rolename
     *            the rolename to set
     */
    public void setRolename(String rolename) {
        this.rolename = rolename;
    }

    /**
     * @return the users
     */
    public Set<Users> getUsers() {
        return users;
    }

    /**
     * @param users
     *            the users to set
     */
    public void setUsers(Set<Users> users) {
        this.users = users;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "Roles [roleid=" + roleid + ", rolename=" + rolename + ", users=" + users + "]";
    }

}
